package com.yjt.fresh.adpater;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yjt.fresh.R;
import com.yjt.fresh.bean.BeanHomePage;
import com.yjt.fresh.bean.BeanUserInfo;

import java.util.List;

/**
 * 首页分类适配器
 * Created by mcc on 2018/6/10.
 */

public class AdpRvMainAtyPersonalPageOrder extends BaseQuickAdapter<BeanHomePage, BaseViewHolder> {

    private BeanUserInfo mUserInfo;
    private boolean mIsLogin;

    public AdpRvMainAtyPersonalPageOrder(int layoutResId, @Nullable List<BeanHomePage> data) {
        super(layoutResId, data);
    }

    public void setUserInfo(BeanUserInfo userInfo){
        mUserInfo = userInfo;
        mIsLogin = true;
        notifyDataSetChanged();
    }

    public void setIsLogin(boolean isLogin){
        mIsLogin = isLogin;
        notifyDataSetChanged();
    }
    @Override
    protected void convert(BaseViewHolder helper, BeanHomePage item) {
        int position = helper.getAdapterPosition();
        TextView tvTitle = helper.getView(R.id.tv_app_recycle_item_personal_order);
        ImageView iv  = helper.getView(R.id.iv_app_recycle_item_personal_order);
        TextView tvMassageCount = helper.getView(R.id.tvAppItemOrderMassageCount);
        RelativeLayout rlMassageCount = helper.getView(R.id.rlAppItemOrderMassageCount);
        switch (position){
            case 0:
                tvTitle.setText("待付款");
                iv.setImageResource(R.mipmap.f_ic_dan_01);
                if (mIsLogin && mUserInfo != null && Integer.valueOf(mUserInfo.getNOT_PAY_ORDER_COUNT()) > 0){
                    rlMassageCount.setVisibility(View.VISIBLE);
                    tvMassageCount.setText(mUserInfo.getNOT_PAY_ORDER_COUNT());
                }else {
                    rlMassageCount.setVisibility(View.GONE);
                }
                break;
            case 1:
                tvTitle.setText("待发货");
                iv.setImageResource(R.mipmap.f_ic_dan_05);
                if (mIsLogin && mUserInfo != null && Integer.valueOf(mUserInfo.getNOT_DELIVERY_ORDER_COUNT()) > 0){
                    rlMassageCount.setVisibility(View.VISIBLE);
                    tvMassageCount.setText(mUserInfo.getNOT_DELIVERY_ORDER_COUNT());
                }else {
                    rlMassageCount.setVisibility(View.GONE);
                }
                break;
            case 2:
                tvTitle.setText("待收货");
                iv.setImageResource(R.mipmap.f_ic_dan_03);
                if (mIsLogin && mUserInfo != null && Integer.valueOf(mUserInfo.getNOT_RECEIPT_ORDER_COUNT()) > 0){
                    rlMassageCount.setVisibility(View.VISIBLE);
                    tvMassageCount.setText(mUserInfo.getNOT_RECEIPT_ORDER_COUNT());
                }else {
                    rlMassageCount.setVisibility(View.GONE);
                }
                break;
            case 3:
                tvTitle.setText("待评价");
                iv.setImageResource(R.mipmap.f_ic_dan_04);
                if (mIsLogin && mUserInfo != null && Integer.valueOf(mUserInfo.getNOT_EVALUATE_ORDER_COUNT()) > 0){
                    rlMassageCount.setVisibility(View.VISIBLE);
                    tvMassageCount.setText(mUserInfo.getNOT_EVALUATE_ORDER_COUNT());
                }else {
                    rlMassageCount.setVisibility(View.GONE);
                }
                break;
            case 4:
                tvTitle.setText("退款/售后");
                iv.setImageResource(R.mipmap.f_ic_dan_02);
                if (mIsLogin && mUserInfo != null && Integer.valueOf(mUserInfo.getBACK_ORDER_COUNT()) > 0){
                    rlMassageCount.setVisibility(View.VISIBLE);
                    tvMassageCount.setText(mUserInfo.getBACK_ORDER_COUNT());
                }else {
                    rlMassageCount.setVisibility(View.GONE);
                }
                break;
        }
    }
}
